import re
filename = '20/20大报告.txt'
dict_name = '20/dict.txt'
target = '20大词频分析.txt'

f = open(dict_name, 'r')
ff = open(filename, 'r')
content = ff.read()
dic = []
dic1 = {}
str1 = f.readlines()
for i in str1:
    dic.append(i.split()[0])
for i in dic:
    if len(i) > 1:
        dic1[i] = content.count(i)
    else:
        continue
tup = dic1.items()
sort1 = sorted(tup, key=lambda x:x[1], reverse=True)
f.close()
ff.close()
f = open(target, 'w')
for i in range(100):
    f.write(sort1[i][0]+'出现了'+str(sort1[i][1])+'次， ')
    if (i + 1) % 5 == 0:
        f.write('\n')
dic2 = {}
pat = re.compile(r'“.+?”')
shuyu = pat.findall(content)
for i in shuyu:
    if i in dic2:
        dic2[i] += 1
    else:
        dic2[i] = 1
tup2 = dic2.items()

for i in tup2:
    print(i[0]+'出现了'+str(i[1])+'次')

print('over')
f.close()



